package me.hys.api.user;

import java.util.List;

import me.hys.api.BaseApi;
import me.hys.base.ApiResult;
import me.hys.base.PageQuery;
import me.hys.bo.company.MessageBo;
import me.hys.bo.company.ProductBo;
import me.hys.bo.doctor.DoctorBo;
import me.hys.entity.doctor.CollectionEntity;
import me.hys.service.doctor.ICollectionManager;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author: @author HYS . <br>
 * Date: 2015-10-11 下午8:54:42 . <br>
 * Function: 收藏
 */
@Controller
@RequestMapping("/api/collection")
public class CollectionApi extends BaseApi {
	@Autowired
	private ICollectionManager collectionManager;

	/**
	 * @Title : delete
	 * @Description : 删除
	 */
	@ResponseBody
	@RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
	public ApiResult delete(@PathVariable int id) {
		return collectionManager.delete(id);
	}

	/**
	 * @Title : deleteByUnionKey
	 * @Description : 删除
	 */
	@ResponseBody
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public ApiResult deleteByUnionKey(@ModelAttribute CollectionEntity entity) {
		return collectionManager.deleteByUnionKey(entity);
	}

	/**
	 * @Title : listDoctor
	 * @Description : 查询医生列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/doctor/{userid}/{start}", method = RequestMethod.GET)
	public List<DoctorBo> listDoctor(@PathVariable int userid,
			@PathVariable int start) {
		PageQuery<DoctorBo> page = getPageQuery(start);
		page.getCondition().put("userId", userid);
		PageQuery<DoctorBo> result = collectionManager.findDoctorPage(page);
		return result.getList();
	}

	/**
	 * @Title : listMessage
	 * @Description : 查询资讯列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/message/{userid}/{start}", method = RequestMethod.GET)
	public List<MessageBo> listMessage(@PathVariable int userid,
			@PathVariable int start) {
		PageQuery<MessageBo> page = getPageQuery(start);
		page.getCondition().put("userId", userid);
		PageQuery<MessageBo> result = collectionManager.findMessagePage(page);
		return result.getList();
	}

	/**
	 * @Title : listProduct
	 * @Description : 查询产品列表
	 */
	@ResponseBody
	@RequestMapping(value = "/list/product/{userid}/{start}", method = RequestMethod.GET)
	public List<ProductBo> listProduct(@PathVariable int userid,
			@PathVariable int start) {
		PageQuery<ProductBo> page = getPageQuery(start);
		page.getCondition().put("userId", userid);
		PageQuery<ProductBo> result = collectionManager.findProductPage(page);
		return result.getList();
	}

	/**
	 * @Title : post
	 * @Description : 保存记录
	 */
	@ResponseBody
	@RequestMapping(value = "/post", method = RequestMethod.POST)
	public ApiResult post(@ModelAttribute CollectionEntity entity) {
		return collectionManager.save(entity);
	}
}
